<template>

	<view class="box">
		<view :style="bj" class="buttonBox1" @click="scan_start">
			开始扫码
		</view>
		<view :style="bj" class="buttonBox1" @click="scan_cancel">
			暂停扫码
		</view>
		<view :style="bj" class="buttonBox1" @click="flash_start">
			灯光
		</view>
		<view :style="bj" class="buttonBox1" @click="scan_close">
			关闭扫码
		</view>

	</view>


</template>

<script>
	import maskModel from './../../components/mask-model/mask-model.vue'

	export default {
		components: {

			maskModel
		},
		data() {
			return {

				headTitleId: true,
				title: "",
				fontcolor: {
					color: this.$kdup.color,
					borderBottom: '2px solid ' + this.$kdup.color
				},
				bj: {
					backgroundColor: this.$kdup.color,
				},
				color: this.$kdup.color,
				list: [],
				barcode: null,
				currentWebview: null,
				flash: false


			}
		},

		//表体初始化  
		onLoad(e) {

			this.eobject = e;
			uni.setNavigationBarColor({
				frontColor: "#ffffff", //文字颜色
				backgroundColor: this.$kdup.color //底部背景色
			})
			this.init(e);
			var flasha = false;
			this.createBarcode();



		},
		//当表体只有一行的时候会报错
		methods: {

			init: function(e) {
				uni.setNavigationBarTitle({
					title: '连续扫码'
				});


			},

			createBarcode: function() {

				var pwidth = '200';
				var sum_width = '0'
				uni.getSystemInfo({
					success: function(res) {
						pwidth = (res.windowWidth - 300) / 2;
						sum_width = res.windowWidth;
					}
				});

				this.currentWebview = this.$mp.page.$getAppWebview(); //注意相关操作写在APP-PLUS条件编译下
				this.barcode = plus.barcode.create('barcode', [plus.barcode.QR], {
					top: '0px',
					left: '0px',
					width: sum_width + 'px',
					height: sum_width + 'px',
					position: 'static'
				}, true);
				this.barcode.onmarked = function(type, result) {
					uni.showToast({
						title: "扫码结果：" + result,
						icon: "none",
						duration: 1000
					});

				};

				this.currentWebview.append(this.barcode);
				this.barcode.start();




			},
			scan_start: function() {
				this.barcode.start();
			},
			scan_cancel: function() {
				this.barcode.cancel();
			},
			scan_close: function() {

				this.barcode.close();
				this.barcode = null;
				this.currentWebview = null;

			},
			flash_start: function() {
				var a = this.flash == true ? false : true;
				this.flash = a;
				this.barcode.setFlash(a);

			},








		}
	}
</script>
<style>
	.box {
		width: 100%;
		height: 84upx;
		display: flex;
		justify-content: center;
		flex-direction: row;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 999;

	}

	.buttonBox1 {
		margin-right: 2rpx;
		width: 50%;
		height: 84upx;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		bottom: 0;
		left: 0;
		right: 0;
	}
</style>
